$(document).ready(function(){
    $("#regButton").click(function(){
        var phone     = $('#regMobile').val();
        var user      = $('#regMobileQ').val();
        var password  = $('#regMobileW').val();
        var pass      = $('#regMobileE').val();
        function clearHint(){   //清除所有提示提示

            $("#phone").text('');
            $("#user").text('');
            $("#password").text('');
            $("#pass").text('');
             }
        clearHint();

        function verify(phone,user,password,pass){
            var price = /^1[34578]\d{9}$/;
            if(!price.test(phone)){
                $('#phone').text('请输入正确的电话号码！');
                return false;
            }
            var re = /^[a-zA-z]\w{3,15}$/;
            if(!re.test(user)){
                $('#user').text('输入4-16个字母、数字、下划线组成，必须字母开头');
                return false;
            }
            var patron = /^\w{8,20}$/;
            if(!patron.test(password)){
                $('#password').text('输入8-20个字母、数字、下划线');
                return false;
            }
            if(password != pass){
                $('#pass').text('两次密码输入不一致');
                return false;
            }
                return true;
        }
        if(verify(phone,user,password,pass)){

            $.ajax({
                type:"post",
                url:"register.php",
                data: {phone:phone,user:user,password:password},
                dataType: "json",   
                success:function( msg){ //php 页面返回值状态
                    if(msg.phone==1){
                        $('#phone').text('号码已注册！');

                    }
                    if(msg.user==1){
                        $('#user').text('用户名已存在！');

                    }
                    if(msg.win==3){
                        window.location.href="/debark.html";
                    }

                }
            });
        }
    });
});
//登陆
$(document).ready(function(){
    $("#regButtonY").click(function(){

        var user      = $('#regMobileQ').val();
        var password  = $('#regMobileW').val();

        function clearHint(){   //清除所有提示提示


            $("#user").text('');
            $("#password").text('');

        }
        clearHint();

        function verify(user,password){

            if(user==''){
                $('#user').text('用户名不能为空！');
                return false;
            }

            if(password==''){
                $('#password').text('密码不能为空！');
                return false;
            }

            return true;
        }
        if(verify(user,password)){

            $.ajax({
                type:"post",
                url:"register.php",
                data: {user:user,password:password},
                dataType: "json",
                success:function( msg){ //php 页面返回值状态
                    if(msg.password==0||msg.user==0){
                        $('#user').text('用户名或者密码错误！');

                    }

                    if(msg.win==2){
                        window.location.href="http://localhost/index.html";
                    }

                }
            });
        }
    });
});
